﻿using Microsoft.Extensions.DependencyInjection;
using WebApiClientCore;
using WebApiClientCore.Attributes;
namespace BPM.Web.Shared.Auth;

/// <summary>
/// Token过滤器
/// </summary>
internal class TokenFilterAttribute : ApiFilterAttribute
{
    public override async Task OnRequestAsync(ApiRequestContext context)
    {
        try
        {
            if (context.HttpContext.ServiceProvider.GetService<ITokenInterceptor>()
                is TokenInterceptor interceptor)
            {
                interceptor.InvokeBeforeSend(context);
            }
        }
        catch { }
        await Task.CompletedTask;
    }

    public override async Task OnResponseAsync(ApiResponseContext context)
    {
        try
        {
            if (context.HttpContext.ServiceProvider.GetService<ITokenInterceptor>()
                is TokenInterceptor interceptor)
            {
                interceptor.InvokeAfterSend(context);
            }
        }
        catch { }
        await Task.CompletedTask;
    }
}

